/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cms.action;

import com.opensymphony.xwork2.ActionSupport;
import com.sun.corba.se.spi.activation.Server;
import dto.Conference;
import dto.Conferenceitem;
import dto.ConferenceitemId;
import dto.User;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import model.ConferenceListDisplayModel;
import model.ConferenceModel;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.aspectj.util.FileUtil;

/**
 *
 * @author Gary
 */
public class UploadAction  extends ActionSupport{
    private File itemFile;
    private String itemFileName;
    private String contentType;
    private String conferenceName;
    private Conference conference;
    private List<Conferenceitem> items;
    private List<User> users;
    private String authorNames;

    public String getAuthorNames() {
        return authorNames;
    }

    public void setAuthorNames(String authorNames) {
        this.authorNames = authorNames;
    }

    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    public List<Conferenceitem> getItems() {
        return items;
    }

    public void setItems(List<Conferenceitem> items) {
        this.items = items;
    }

    public List<ConferenceListDisplayModel> getDisplayItems() {
        return displayItems;
    }

    public void setDisplayItems(List<ConferenceListDisplayModel> displayItems) {
        this.displayItems = displayItems;
    }
    private List<ConferenceListDisplayModel> displayItems; 

    public Conference getConference() {
        return conference;
    }

    public void setConference(Conference conference) {
        this.conference = conference;
    }
    public String getConferenceName() {
        return conferenceName;
    }

    public void setConferenceName(String conferenceName) {
        this.conferenceName = conferenceName;
    }

    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    public String getItemFileName() {
        return itemFileName;
    }

    public void setItemFileName(String itemFileName) {
        this.itemFileName = itemFileName;
    }

    public File getItemFile() {
        return itemFile;
    }

    public void setItemFile(File itemFile) {
        this.itemFile = itemFile;
    }
    public UploadAction() {
    }
    
    public String upload() throws IOException
    {
        try {
           File uoloadedFile = this.getItemFile();
           System.out.println(authorNames);
           List<String> coauthors = Arrays.asList(authorNames.split(","));
           return "uploaded";          
        } catch (Exception e) {
            e.printStackTrace();
            addActionError(e.getMessage());
            return "input";
        }       
    } 

     public String toupload()
    {  
        conference = new Conference(conferenceName, "Siminar", "Sands Hotel", true, null, true, 99.90,128);
        items = new ArrayList<Conferenceitem>();
        ConferenceitemId id  = new ConferenceitemId(this.conferenceName,"Item1");
        items.add(new Conferenceitem(id,"Item Desc 1",1,"sb.html",1,(double)10,false));
        id  = new ConferenceitemId(this.conferenceName,"Item2");
        items.add(new Conferenceitem(id,"Item Desc 2",2,"sb.html",2,(double)20,false));
        id  = new ConferenceitemId(this.conferenceName,"Item3");
        items.add(new Conferenceitem(id,"Item Desc 3",3,"sb.html",3,(double)30,false));
        displayItems = ConferenceModel.ConverModelList(items);
        users = new ArrayList<User>();
        users.add(new User("EiChaw", "", "member"));
        users.add(new User("Daobo", "", "member"));
        users.add(new User("Hongxiang", "", "member"));
        users.add(new User("Garry", "", "member"));
        return "input";
    }        
}
